import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;


public class TesteWeb {
	
	public static void main(String[] args) throws IOException {
		
		String strurl = "http://noticias.gov.br/";
		
		try
		{
			System.out.println(isOnline(strurl));
		}
		catch(MalformedURLException e)
		{
			System.out.println("ERRO NA ESCRITA DA URL");
		}
		
	}
	

	public static boolean isOnline(String strurl) throws IOException
	{
		URL url = new URL(strurl);
		
		long time_inicial = (new Date()).getTime();
		
		URLConnection connection =  url.openConnection();
		
		String status = connection.getHeaderField(null);
		String header = connection.getHeaderFields().toString();
		
		long time_final = (new Date()).getTime();
		long duracao = time_final - time_inicial;
		
		System.out.println(duracao + " ms");
		
		return status.contains("OK");
	}
	
}
